<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/2/28
 * Time: 15:19
 */

namespace App\Http\Controllers\Admin;


use App\Http\Logics\Admin\CategoryLogic;
use App\Http\Traits\CategoryTrait;
use App\Http\Controllers\BaseController;
class CategoryController extends BaseController
{
    use CategoryTrait;

    /**
     * 获取分类列表
     * @return string
     */
    public function getCategoryList()
    {
        $parent_id = $this->parent_id;
        $data = [
            'parent_id' => $parent_id
        ];
        $response = CategoryLogic::getCategoryList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 分类排序
     * @return string
     */
    public function setSort()
    {
        $new_sort_str = $this->new_sort_str;
        $data = [
            'new_sort_str' => $new_sort_str
        ];
        $response = CategoryLogic::setSort($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function createCategory()
    {
        $parent_id = $this->parent_id;
        $name = $this->name;
        $icon = $this->icon;
        $banner = $this->banner;
        $data = [
            'name' => $name,
            'icon' => $icon,
            'parent_id' => $parent_id,
            'banner' => $banner
        ];
        $response = CategoryLogic::createCategory($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 上传城市封面
     * @return string
     */
    public function uploadIcon()
    {
        $icon_file = $this->icon_file;
        $data = [
            'icon_file' => $icon_file
        ];
        $response = CategoryLogic::uploadIcon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function deleteCategory()
    {
        $category_id = $this->category_id;
        $data = [
            'category_id' => $category_id
        ];
        $response = CategoryLogic::deleteCategory($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function updateCategory()
    {
        $category_id = $this->category_id;
        $name = $this->name;
        $icon = $this->icon;
        $banner = $this->banner;
        $data = [
            'category_id' => $category_id,
            'name' => $name,
            'icon' => $icon,
            'banner' => $banner
        ];
        $response = CategoryLogic::updateCategory($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function getCategoryDetail()
    {
        $category_id = $this->category_id;
        $data = [
            'category_id' => $category_id
        ];
        $response = CategoryLogic::getCategoryDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function changeStatus()
    {
        $category_id = $this->category_id;
        $data = [
            'category_id' => $category_id
        ];
        $response = CategoryLogic::changeStatus($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}